<?php
declare (strict_types = 1);

namespace app\api\controller\order;

use app\api\controller\Base;
use app\common\service\OrderService;
use think\exception\ValidateException;
use think\Request;

class Refund extends Base
{
    /**
     * Author:Yingbo Sun
     * 申请退款
     * @return mixed
     */
    public function refund()
    {
        $refundInfo = $this->request->post();
        try {
            validate(\app\validate\Refund::class)->check([
                'order_id'  => $refundInfo['order_id'],
                'refund_price'   => $refundInfo['refund_price'],
                'refund_reason_wap_explain' => $refundInfo['refund_reason_wap_explain'],
                'refund_reason_wap_img' => $refundInfo['refund_reason_wap_img'],
                'refund_reason_wap' => $refundInfo['refund_reason_wap'],
            ]);
        } catch (ValidateException $e) {
            // 验证失败 输出错误信息
            $data = ['code' => 400,'message'=>$e->getError()];
            return $this->res($data);
        }
        $res = OrderService::refund($refundInfo);
        return $this->res($res);
    }

    /**
     * Author:Yingbo Sun
     * 取消退款
     * @return mixed
     */
    public function cancelTheRefund()
    {
        $post = $this->request->post();
        $res = OrderService::cancelRefund($post);
        return $this->res($res);
    }

}
